package com.aspose.cells;

public class zcfx {
   private static char[] a = new char[]{' ', '/', '>'};
   private static char[] b = new char[]{'<', '/'};
   private boolean c = false;
   private boolean[] d;
   private boolean[] e;
   private String[] f;
   private int g;
   private com.aspose.cells.b.a.d.zr h;
   private int i;
   private char[] j;
   private boolean k = false;
   private char[] l;
   private int m;
   private static byte[] n;

   public zcfx(com.aspose.cells.b.a.d.zm var1, Encoding var2) throws Exception {
      this.h = new com.aspose.cells.b.a.d.zo(var1, var2);
      this.i();
   }

   public zcfx(StringBuilder var1) throws Exception {
      this.h = new com.aspose.cells.b.a.d.zp(var1);
      this.i();
   }

   public zcfx(com.aspose.cells.b.a.d.zo var1) {
      this.h = var1;
      this.i();
   }

   public void a(String var1, String var2) throws Exception {
      this.h.a(' ');
      this.h.a(var1);
      this.h.a('=');
      this.h.a('"');
      if (var2 != null) {
         this.b(var2, true);
      }

      this.h.a('"');
   }

   public void a(String var1, String var2, String var3) throws Exception {
      this.h.a(' ');
      this.h.a(var1);
      this.h.a('=');
      this.h.a('"');
      if (var3 != null) {
         this.b(var3, true);
      }

      this.h.a('"');
   }

   public void a(String var1, String var2, String var3, String var4) throws Exception {
      this.h.a(' ');
      if (var1 == null) {
         this.h.a(var2);
      } else if (var2 == null) {
         this.h.a(var1);
      } else {
         this.h.a(var1);
         this.h.a(':');
         this.h.a(var2);
      }

      this.h.a('=');
      this.h.a('"');
      if (var4 != null) {
         this.b(var4, true);
      }

      this.h.a('"');
   }

   public void a(String var1, String var2, String var3, String var4, boolean var5) throws Exception {
      this.h.a(' ');
      if (var1 == null) {
         this.h.a(var2);
      } else if (var2 == null) {
         this.h.a(var1);
      } else {
         this.h.a(var1);
         this.h.a(':');
         this.h.a(var2);
      }

      this.h.a('=');
      this.h.a('"');
      if (var4 != null) {
         if (var5) {
            this.b(var4, true);
         } else {
            this.h.a(var4);
         }
      }

      this.h.a('"');
   }

   private void e(boolean var1) throws Exception {
      if (this.c) {
         this.h.a('>');
         this.c = false;
      }

      if (this.i == 1 && this.g > 0) {
         this.h.f();
         this.h.a(this.j, 0, this.g);
      }

   }

   private void f(boolean var1) throws Exception {
      if (this.c) {
         this.h.a('>');
         this.c = false;
      }

      if (this.i == 1) {
         this.h.f();
         if (this.g > 0) {
            this.h.a(this.j, 0, this.g);
         }
      }

   }

   public void a(String var1) throws Exception {
      if (var1 != null && var1.length() != 0) {
         if (this.c) {
            this.h.a('>');
            this.c = false;
         }

         this.b(var1, false);
      }
   }

   public void a(String var1, boolean var2) throws Exception {
      if (this.c) {
         this.h.a('>');
         this.c = false;
      }

      if (var2) {
         this.b(var1, false);
      } else {
         this.h.a(var1);
      }

   }

   public void b(String var1, String var2) throws Exception {
      this.b((String)null, var1, (String)null, var2, true);
   }

   public void b(String var1, String var2, String var3) throws Exception {
      this.b((String)null, var1, var2, var3, true);
   }

   public void b(String var1, String var2, String var3, String var4, boolean var5) throws Exception {
      this.e(true);
      if (this.g > 0) {
         this.d[this.g - 1] = true;
      }

      String var6 = var2;
      if (var1 != null) {
         var6 = var1 + ":" + var2;
      }

      this.h.a('<');
      this.h.a(var6);
      if (var4 != null && !"".equals(var4)) {
         this.h.a('>');
         if (var5) {
            this.b(var4, false);
         } else {
            this.h.a(var4);
         }

         this.h.a(b, 0, 2);
         this.h.a(var6);
         this.h.a('>');
      } else {
         this.h.a(a, 0, a.length);
      }

   }

   public void b(String var1, String var2, String var3, String var4) throws Exception {
      this.b(var1, var2, var3, var4, true);
   }

   public void b(String var1) throws Exception {
      this.c((String)null, var1, (String)null);
   }

   public void c(String var1, String var2) throws Exception {
      this.c((String)null, var1, var2);
   }

   public void c(String var1, String var2, String var3) throws Exception {
      this.e(true);
      this.h.a('<');
      String var4 = var2;
      if (var1 != null) {
         var4 = var1 + ":" + var2;
      }

      this.h.a(var4);
      if (this.g > 0) {
         this.d[this.g - 1] = true;
      }

      this.f[this.g++] = var4;
      this.c = true;
   }

   public void a(String var1, String var2, boolean var3) throws Exception {
      this.e(true);
      this.h.a('<');
      String var4 = var2;
      if (var1 != null) {
         var4 = var1 + ":" + var2;
      }

      if (var3) {
         this.e(var4);
      } else {
         this.h.a(var4);
      }

      if (this.g > 0) {
         this.d[this.g - 1] = true;
      }

      this.f[this.g++] = var4;
      this.c = true;
   }

   public void a() throws Exception {
      --this.g;
      if (this.c) {
         this.h.a('>');
         this.c = false;
      } else if (this.d[this.g]) {
         this.f(true);
         this.d[this.g] = false;
      }

      String var1 = this.f[this.g];
      this.h.a(b, 0, 2);
      this.h.a(var1);
      this.h.a('>');
   }

   public void c(String var1) throws Exception {
      this.e(true);
      this.h.a("<!--");
      this.h.a(var1);
      this.h.a("-->");
   }

   public void b() throws Exception {
      --this.g;
      if (this.c) {
         this.h.a(a, 0, a.length);
         this.c = false;
      } else {
         if (this.d[this.g]) {
            this.f(true);
            this.d[this.g] = false;
         }

         String var1 = this.f[this.g];
         this.h.a(b, 0, 2);
         this.h.a(var1);
         this.h.a('>');
      }

   }

   public void a(boolean var1) throws Exception {
      --this.g;
      if (this.c) {
         this.h.a(a, 0, a.length);
         this.c = false;
      } else {
         if (this.d[this.g]) {
            this.f(true);
            this.d[this.g] = false;
         }

         String var2 = this.f[this.g];
         this.h.a(b, 0, 2);
         if (var1) {
            this.e(var2);
         } else {
            this.h.a(var2);
         }

         this.h.a('>');
      }

   }

   public void c() throws Exception {
      this.h.a("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
   }

   public void b(boolean var1) throws Exception {
      if (var1) {
         this.h.a("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
      } else {
         this.h.a("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      }

      if (this.i == 1) {
         this.h.f();
      }

   }

   public void d() throws Exception {
      if (this.i == 1) {
         this.h.f();
      }

   }

   public void d(String var1) throws Exception {
      this.e(var1 != null && !"".equals(var1) ? var1.charAt(0) == '<' : false);
      this.h.a(var1);
   }

   public void e() throws Exception {
      this.h.c();
   }

   public void f() throws Exception {
      this.h.b();
   }

   private void e(String var1) throws Exception {
      if (var1 != null) {
         char[] var2 = var1.toCharArray();
         int var3 = 0;
         boolean var4 = false;

         for(int var5 = 0; var5 < var2.length; ++var5) {
            char var9 = var2[var5];
            switch(var9) {
            case '\n':
            case '\r':
            case ' ':
            case '"':
            case '&':
            case '\'':
            case '(':
            case ')':
            case '.':
            case '/':
            case '<':
            case '>':
            case '?':
            case '\\':
               if (var5 - var3 > 0) {
                  this.h.a(var2, var3, var5 - var3);
               }

               this.h.a("_x");
               this.h.a(com.aspose.cells.a.c.zp.d(var9));
               this.h.a('_');
               var3 = var5 + 1;
               break;
            case ':':
               if (var5 == var2.length - 1) {
                  if (var5 - var3 > 0) {
                     this.h.a(var2, var3, var5 - var3);
                  }

                  this.h.a("_x");
                  this.h.a(com.aspose.cells.a.c.zp.d(var9));
                  this.h.a('_');
                  var3 = var5 + 1;
               }
               break;
            case '_':
               if (!this.k || var5 + 6 >= var2.length || var2[var5 + 1] != 'x' || var2[var5 + 6] != '_') {
                  break;
               }

               boolean var6 = true;

               for(int var7 = var5 + 2; var7 < var5 + 6; ++var7) {
                  char var8 = var2[var7];
                  if (!zcfi.a(var8)) {
                     var6 = false;
                     break;
                  }
               }

               if (var6) {
                  if (var5 - var3 > 0) {
                     this.h.a(var2, var3, var5 - var3);
                  }

                  this.h.a("_x005F_");
                  var3 = var5 + 1;
               }
               break;
            default:
               if ((n[var9 = var2[var5]] & 255 & 128) == 0) {
                  if (var5 - var3 > 0) {
                     this.h.a(var2, var3, var5 - var3);
                  }

                  if (this.k) {
                     this.h.a("_x");
                     this.h.a(com.aspose.cells.a.c.zp.d(var9));
                     this.h.a('_');
                  } else if (var9 >= '\ud800' && var9 <= '\udbff') {
                     if (var3 + 1 >= this.m) {
                        throw new zcfn("Xml_SurrogatePairSplit");
                     }

                     this.h.a(var9);
                     ++var5;
                     this.h.a(var2[var5]);
                  } else {
                     this.h.a("&#x");
                     this.h.a(com.aspose.cells.a.c.zp.d(var9));
                     this.h.a(';');
                  }

                  var3 = var5 + 1;
               }
            }
         }

         if (var3 < var2.length) {
            this.h.a(var2, var3, var2.length - var3);
         }

      }
   }

   private void b(String var1, boolean var2) throws Exception {
      if (var1 != null) {
         char[] var3 = var1.toCharArray();
         int var4 = 0;
         boolean var5 = false;

         for(int var6 = 0; var6 < var3.length; ++var6) {
            char var10;
            if ((n[var10 = var3[var6]] & 255 & 128) == 0) {
               switch(var10) {
               case '\n':
                  if (var2) {
                     if (var6 - var4 > 0) {
                        this.h.a(var3, var4, var6 - var4);
                     }

                     if (this.k) {
                        this.h.a("_x000a_");
                     } else {
                        this.h.a("&#x000a;");
                     }

                     var4 = var6 + 1;
                  }
                  break;
               case '\r':
                  if (!var2 && var6 + 1 < var3.length && var3[var6 + 1] == '\n') {
                     break;
                  }

                  if (var6 - var4 > 0) {
                     this.h.a(var3, var4, var6 - var4);
                  }

                  if (this.k) {
                     this.h.a("_x000d_");
                  } else {
                     this.h.a("&#x000d;");
                  }

                  var4 = var6 + 1;
                  break;
               case '"':
                  if (var2) {
                     if (var6 - var4 > 0) {
                        this.h.a(var3, var4, var6 - var4);
                     }

                     this.h.a("&quot;");
                     var4 = var6 + 1;
                  }
                  break;
               case '&':
                  if (var6 - var4 > 0) {
                     this.h.a(var3, var4, var6 - var4);
                  }

                  this.h.a("&amp;");
                  var4 = var6 + 1;
               case '\'':
                  break;
               case '<':
                  if (var6 - var4 > 0) {
                     this.h.a(var3, var4, var6 - var4);
                  }

                  this.h.a("&lt;");
                  var4 = var6 + 1;
                  break;
               case '>':
                  if (var6 - var4 > 0) {
                     this.h.a(var3, var4, var6 - var4);
                  }

                  this.h.a("&gt;");
                  var4 = var6 + 1;
                  break;
               case '_':
                  if (!this.k || var6 + 6 >= var3.length || var3[var6 + 1] != 'x' || var3[var6 + 6] != '_') {
                     break;
                  }

                  boolean var7 = true;

                  for(int var8 = var6 + 2; var8 < var6 + 6; ++var8) {
                     char var9 = var3[var8];
                     if (!zcfi.a(var9)) {
                        var7 = false;
                        break;
                     }
                  }

                  if (var7) {
                     if (var6 - var4 > 0) {
                        this.h.a(var3, var4, var6 - var4);
                     }

                     this.h.a("_x005F_");
                     var4 = var6 + 1;
                  }
                  break;
               default:
                  if (var6 - var4 > 0) {
                     this.h.a(var3, var4, var6 - var4);
                  }

                  if (var10 >= '\ud800' && var10 <= '\udbff') {
                     if (var4 + 1 >= var3.length) {
                        throw new zcfn("Xml_SurrogatePairSplit");
                     }

                     this.h.a(var10);
                     ++var6;
                     this.h.a(var3[var6]);
                  } else if (this.k) {
                     this.h.a("_x");
                     this.h.a(com.aspose.cells.a.c.zp.d(var10));
                     this.h.a('_');
                  } else {
                     this.h.a("&#x");
                     this.h.a(com.aspose.cells.a.c.zp.d(var10));
                     this.h.a(';');
                  }

                  var4 = var6 + 1;
               }
            }
         }

         if (var4 < var3.length) {
            this.h.a(var3, var4, var3.length - var4);
         }

      }
   }

   private void i() {
      this.j = com.aspose.cells.b.a.zv.a(' ', 256).toCharArray();
      this.c = false;
      this.d = new boolean[256];
      this.f = new String[256];
      this.i = 0;
      this.e = new boolean[1];
      this.m = 4096;
      this.l = new char[this.m];
      if (n == null) {
         n = new byte[65536];
         byte[] var1 = n;
         synchronized(n) {
            byte[] var2 = com.aspose.cells.a.c.zv.f();
            System.arraycopy(var2, 0, n, 0, var2.length);
         }
      }

   }

   public int g() {
      return this.i;
   }

   public void a(int var1) {
      this.i = var1;
   }

   public void a(char var1) {
      this.j = com.aspose.cells.b.a.zv.a(var1, 256).toCharArray();
   }

   public boolean h() {
      return this.k;
   }

   public void c(boolean var1) {
      this.k = var1;
   }

   public void b(int var1) {
   }

   public void d(boolean var1) {
   }
}
